package common.utils
{
	public class DigitUtil
	{		
		public static function twoDigitFormatter(n:Number):String
        {
            if (n < 10){
                return (("0" + n.toString()));
            };
            
            return (n.toString());
        }
        
		public static function getHumanHistoryTime(timestamp:uint,showNum:int=2):String
        {
        	var date:Date = new Date();
        	
        	var timeNow:uint = uint(date.time/1000);
        	
        	var timeInter:int = (timeNow - timestamp)>0?(timeNow - timestamp):3;
        
        	var humenStr:String="";
        	var count:int = 0;
        	var num:int;
        	
        	while(count<showNum && timeInter>0)
        	{
	        	if (timeInter > (24*3600*365))
	        	{
	        		//year
	        		num = Math.floor(timeInter/(24*3600*365));
	        		timeInter = timeInter - num*(24*3600*365);
	        		
	        		humenStr += num.toString() + "年";
	        	}
	        	else if (timeInter > (24*3600*30))
	        	{
	        		//month
	        		num = Math.floor(timeInter/(24*3600*30));
	        		timeInter = timeInter - num*(24*3600*30);
	        		
	        		humenStr += num.toString() + "月";        		
	        	}
	        	else if (timeInter > (24*3600*7))
	        	{
	        		//week
	        		num = Math.floor(timeInter/(24*3600*7));
	        		timeInter = timeInter - num*(24*3600*7);
	        		
	        		humenStr += num.toString() + "周";	        		
	        	}
	        	else if (timeInter > (24*3600))
	        	{
	        		//day
	        		num = Math.floor(timeInter/(24*3600));
	        		timeInter = timeInter - num*(24*3600);
	        		
	        		humenStr += num.toString() + "天";	        		
	        	}
	        	else if (timeInter > (3600))
	        	{
	        		//hour
	        		num = Math.floor(timeInter/3600);
	        		timeInter = timeInter - num*3600;
	        		
	        		humenStr += num.toString() + "小时";	        		
	        	}
	        	else if (timeInter > (60))
	        	{
	        		//minute
	        		num = Math.floor(timeInter/60);
	        		timeInter = timeInter - num*60;
	        		
	        		humenStr += num.toString() + "分";        		
	        	}
	        	else
	        	{
	        		humenStr += timeInter.toString() + "秒";
	        		timeInter = 0;   		
	        	}
	        	
	        	count++;        		        		        		     		        	
        	}
        	
        	return humenStr;  
        }        
	}
}